using System.Windows;
using System.Windows.Media;

namespace TabControlLib.Tools
{
    public static class VisualHelper
    {
        public static T GetParent<T>(DependencyObject obj) where T : DependencyObject
        {
            while (obj != null)
            {
                if (obj is T parent)
                {
                    return parent;
                }

                obj = VisualTreeHelper.GetParent(obj);
            }

            return null;
        }

        public static Point GetOffset(FrameworkElement element)
        {
            var transform = element.RenderTransform as TranslateTransform;
            return transform == null ? new Point() : new Point(transform.X, transform.Y);
        }
    }
}
